import requests
import re
from urllib import parse
from lxml import etree

class BaiDuPicture:
    def __init__(self,keyword,page=1):
        self.url = 'https://www.baidu.com/s?wd={}'.format(keyword)
        url_keyword = parse.quote(keyword)
        self.url2 = 'http://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gb18030&word={}&fr=ala&ala=1&alatpl=adress&pos=0&hs=2&xthttps=000000'.format(url_keyword)
        self.pn = page
        self.headers= {
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.6776.400 QQBrowser/10.3.2577.400'
        }
    def my_xpath(self,data,ruler):
        return etree.HTML(data).xpath(ruler)
    def request_url(self,url):
        self.session = requests.session()
        res = self.session.get(url=url,headers=self.headers,verify=False)
        # print(res.text)
        return res.text
    def get_picture_page(self):
        resp = self.request_url(self.url)
        print(resp)
if __name__ == '__main__':
    bp = BaiDuPicture('动漫头像女')
